home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / mach / lock-intern.h < prev    next >
C/C++ Source or Header  |  1994-05-16  |  3KB  |  90 lines

  1. /* Copyright (C) 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef _LOCK_INTERN_H
  20. #define    _LOCK_INTERN_H
  21.  
  22. #include <machine-lock.h>
  23.  
  24. #ifndef _EXTERN_INLINE
  25. #define _EXTERN_INLINE extern __inline
  26. #endif
  27.  
  28.  
  29. /* Initialize LOCK.  */
  30.  
  31. _EXTERN_INLINE void
  32. __spin_lock_init (__spin_lock_t *__lock)
  33. {
  34.   *__lock = __SPIN_LOCK_INITIALIZER;
  35. }
  36.  
  37.  
  38. /* Lock LOCK, blocking if we can't get it.  */
  39. extern void __spin_lock_solid (__spin_lock_t *__lock);
  40.  
  41. /* Lock the spin lock LOCK.  */
  42.  
  43. _EXTERN_INLINE void
  44. __spin_lock (__spin_lock_t *__lock)
  45. {
  46.   if (! __spin_try_lock (__lock))
  47.     __spin_lock_solid (__lock);
  48. }
  49.  
  50. /* Name space-clean internal interface to mutex locks.  
  51.  
  52.    Code internal to the C library uses these functions to lock and unlock
  53.    mutex locks.  These locks are of type `struct mutex', defined in
  54.    <cthreads.h>.  The functions here are name space-clean.  If the program
  55.    is linked with the cthreads library, `__mutex_lock_solid' and
  56.    `__mutex_unlock_solid' will invoke the corresponding cthreads functions
  57.    to implement real mutex locks.  If not, simple stub versions just use
  58.    spin locks.  */
  59.  
  60.  
  61. /* Initialize the newly allocated mutex lock LOCK for further use.  */
  62. extern void __mutex_init (void *__lock);
  63.  
  64. /* Lock LOCK, blocking if we can't get it.  */
  65. extern void __mutex_lock_solid (void *__lock);
  66.  
  67. /* Finish unlocking LOCK, after the spin lock LOCK->held has already been
  68.    unlocked.  This function will wake up any thread waiting on LOCK.  */
  69. extern void __mutex_unlock_solid (void *__lock);
  70.  
  71. /* Lock the mutex lock LOCK.  */
  72.  
  73. _EXTERN_INLINE void
  74. __mutex_lock (void *__lock)
  75. {
  76.   if (! __spin_try_lock ((__spin_lock_t *) __lock))
  77.     __mutex_lock_solid (__lock);
  78. }
  79.  
  80. /* Unlock the mutex lock LOCK.  */
  81.  
  82. _EXTERN_INLINE void
  83. __mutex_unlock (void *__lock)
  84. {
  85.   __spin_unlock ((__spin_lock_t *) __lock);
  86.   __mutex_unlock_solid (__lock);
  87. }
  88.  
  89. #endif /* lock-intern.h */
  90.